package gbench.sandbox.data.index;

import java.util.HashMap;
import java.util.function.BiFunction;

import gbench.common.matlib.algebra.lisp.IRecord;

/**
 * 
 *  表-算法
 * table->IndexEngine
 * 
 * @author Administrator
 *
 */
public class TableAlgorithm extends HashMap<String, IndexEngine> {

    /**
     * 
     * @param alogrithm
     */
    public TableAlgorithm(final Algorithm alogrithm, final ITableSearchEngine srchEngine) {
        super();
        this.algorithm = alogrithm;
        this.srchEngine = srchEngine;
    }

    /**
     * 
     * @return
     */
    public Algorithm getAlgorithm() {
        return algorithm;
    }

    /**
     * 创建索引引擎
     * 
     * @param table 表名
     * @param index_creator 索引创建器
     * @return IndexEngine
     */
    public IndexEngine addIndexEngine(final String table, final BiFunction<Algorithm, IRecord, String[]> index_creator) {
        return this.computeIfAbsent(table, tbl -> new IndexEngine(this, tbl, index_creator));
    }

    /**
     * 提取 索引引擎
     * 
     * @param table 表名
     * @return IndexEngine
     */
    public IndexEngine getEngine(final String table) {
        return this.get(table);
    }

    /**
     * 获取 表索引算法 x 表  矩阵
     * 
     * @return
     */
    public ITableSearchEngine getMatrix() {
        return srchEngine;
    }

    private final Algorithm algorithm;
    private ITableSearchEngine srchEngine;

    private static final long serialVersionUID = -8452826490757186016L;

}
